package com.czy.utilslib.network;

import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

public class ResponseTool {

    public static final String SUCCESS_CODE = "200";

    public static boolean handleRespond(BaseResponse response, Context context){
        if(response != null && response.getCode() != null){
            if (response.getCode().equals(SUCCESS_CODE)){
                return true;
            }
            else {
                if(context instanceof Activity){
                    ((Activity) context).runOnUiThread(() -> Toast.makeText(context, response.getMessage(), Toast.LENGTH_SHORT).show());
                }
                return false;
            }
        }
        else {
            if(context instanceof Activity){
                ((Activity) context).runOnUiThread(() -> Toast.makeText(context, "网络连接失败", Toast.LENGTH_SHORT).show());
            }
            return false;
        }
    }
}
